
const Rxjs = require('rxjs');
const Operators = require('rxjs/operators');
const { Observable, interval, take } = Rxjs;
const { map, filter,reduce,find,findIndex } = Operators;

const observable = new Observable(subscriber => {
    // subscriber.next(1);
    // subscriber.next(2);
    // subscriber.next(3);
    
    // setTimeout(() => {
    //     subscriber.next(4);
    //     subscriber.complete();
    // }, 1000);
});

// observable.subscribe({
//     next:(value) => {
//         console.log(value);
//     }
// });

// interval 五百毫秒执行一次pipe就是管道的意思 管道里边也可以调取接口，支持一部数据处理
// map和filter跟数组的方法是一样的，最后通过观察者subscribe接受回调
const subs = interval(500).pipe(map(v => ({ num: v })), filter(v => (v.num % 2 == 0))).subscribe((e) => {
    console.log(e)
    if (e.num == 10) {
        subs.unsubscribe()
    }
});